<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of adminview
 *
 * @author baleia
 */
class AdminView{

    private static $controlador = AdminController;

    public function __construct(){
              self::$controlador = new AdminController;
              header("Content-Type: text/html; charset=UTF8", true);

    }

    public function cadastroDisciplina(){
              echo   '<head>
                      <meta http-equiv="content-Type" content="text/html; charset=UTF8" />
                      </head>
                      <br/><h2> Nova Disciplina </h2>
                      <form action="index.php" method="post">
                      <input type="hidden" name="funcao" value="ResultadoCadastroDisciplina">
                      <table cellpadding="0" cellspacing="0" border="0" class="form_table">
                      <tr>
                      <td valign="middle" align="right">Nome:</td>
                      <td valign="middle" align="left">
                      <input name="nome" type="text" class="inputgri" maxlength="100"/>
                      </td>
                      </tr>
                      <tr>
                      <td valign="middle" align="right">Código da Disciplina:</td>
                      <td valign="middle" align="left">
                      <input name="id" type="text" class="inputgri" maxlength="6"/>
                      </td>
                      </tr>
                      </table>
                      <p><input type="submit" class="button" value="Salvar" />
                      </form>
                      <form action="index.php" method="post">
                      <input type="hidden" name="funcao" value="listaDisciplina">
                      <input type="submit" class="button" value="Cancelar" /></p>
                      </form>';
    }

    public function resultadoCadastroDisciplina(){
                    $disciplina = new Disciplina;
                    $disciplina->nome=$_POST['nome'];
                    $disciplina->id=$_POST['id'];
                    self::$controlador->salvar($disciplina);
                    echo '<font color="green">Disciplina cadastrada com sucesso!!</font><br/>';
                    $this->listaDisciplina();

    }

    public function buscaDisciplina(){
                echo '<head>
                      <meta http-equiv="content-Type" content="text/html; charset=UTF8" />
                      </head>
                      <br/><h2> Pesquisa por Disciplina </h2>
                      <form name="formBusca" action="index.php" method="post">
                      <input type="hidden" name="funcao" value="ResultadoBuscaDisciplina">
                      <table cellpadding="0" cellspacing="0" border="0" class="form_table">
                      <tr>
                      <td valign="middle" align="right">Código da Disciplina:</td>
                      <td valign="middle" align="left">
                      <input name="id" type="text" class="inputgri" maxlength="6"/>
                      </td>
                      </tr>
                      </table>
                      <p><input type="submit" class="button" value="Pesquisar" /></p>
                      </form>';
    }

    public function resultadoBuscaDisciplina(){
                $disciplina=self::$controlador->buscar($_POST['id'],'Disciplina');
                echo '<head>
                      <meta http-equiv="content-Type" content="text/html; charset=UTF8" />
                      </head>
                      <br/><h2> Detalhes da Disciplina </h2>
                      <form name="formRBusca" action="index.php" method="post">
                      <input type="hidden" name="funcao" value="resultadoExcluirDisciplina">
                      <input type="hidden" name="id" value="'.$disciplina->id.'">
                      <table cellpadding="0" cellspacing="0" border="0" class="form_table">
                      <tr>
                      <td valign="middle" align="right">Nome:</td>
                      <td valign="middle" align="left">'.$disciplina->nome.'</td>
                      </tr>
                      <tr>
                      <td valign="middle" align="right">Código da Disciplina:
                      </td>
                      <td valign="middle" align="left">'.$disciplina->id.'</td>
                      </tr>
                      </table>
                      <p><input type="submit" class="button" value="Excluir" /></p>
                      </form>';
    }

    public function listaDisciplina(){
              echo '<br/><h2> Lista de Disciplinas </h2>
                    <form name="formLista" action="index.php" method="post">
                    <input type="hidden" name="funcao" value="">
                    <input type="hidden" name="id" value="">
                    <table cellpadding="0" cellspacing="0" border="0" width="100%" class="table">
                    <!-- table header -->
                    <tr class="table_header">
                        <td valign="middle" align="left">Código da Disciplina</td>
                        <td valign="middle" align="left">Nome da Disciplina</td>
                        <td valign="middle" align="left">Opções</td>
                    </tr>';
                    $disciplinas=self::$controlador->listar('Disciplina');
                    foreach ($disciplinas as $disciplina)
                    {
                        echo '<!-- row type one -->
                              <tr class="row1">
                              <td valign="middle" align="left">'.$disciplina->id.'</td>
                              <td valign="middle" align="left"><a"><div OnClick="document.formLista.funcao.value='."'resultadoBuscaDisciplina'".'; document.formLista.codigo.value='."'".$disciplina->id."'".'; document.formLista.submit();">'.$disciplina->nome.'</div></a></td>
                              <td valign="middle" align="left"><a href="#"><div OnClick="document.formLista.funcao.value='."'resultadoExcluirDisciplina'".'; document.formLista.id.value='."'".$disciplina->id."'".'; document.formLista.submit();">Excluir</div></a></td>
                              </tr>';
                    }
                    echo '</table>
                          </form>
                    <form action="index.php" method="post">
                      <input type="hidden" name="funcao" value="cadastroDisciplina">
                      <input type="submit" class="button" value="Nova Disciplina" /></p>
                      </form>';
    }

    public function resultadoExcluirDisciplina(){
                    self::$controlador->excluir($_POST['id'],'Disciplina');
                    echo '<font color="green">Disciplina excluída com sucesso!!</font><br/>';
                    $this->listaDisciplina();
    }


    // Métodos que redirecionam para páginas de manipulação
    // da entidade Turma
    public function buscaTurma(){
                echo '<head>
                      <meta http-equiv="content-Type" content="text/html; charset=UTF8" />
                      </head>
                      <br/><h2> Pesquisa por Turma </h2>
                      <form name="formBusca" action="index.php" method="post">
                      <input type="hidden" name="funcao" value="resultadoBuscaTurma">
                      <table cellpadding="0" cellspacing="0" border="0" class="form_table">
                      <tr>
                      <td valign="middle" align="right">Código da Disciplina:</td>
                      <td valign="middle" align="left">
                      <input name="idDisciplina" type="text" class="inputgri" />
                      </td>
                      </tr>
                      <tr>
                      <td valign="middle" align="right">Código da Turma:</td>
                      <td valign="middle" align="left">
                      <input name="idTurma" type="text" class="inputgri" />
                      </td>
                      </tr>
                      </table>
                      <p><input type="submit" class="button" value="Pesquisar" /></p>
                      </form>';
    }

    public function cadastroTurma(){
                echo '<head>
                      <meta http-equiv="content-Type" content="text/html; charset=UTF8" />
                      </head>
                      <br/><h2> Nova Turma </h2>
                      <form action="index.php" method="post">
                      <input type="hidden" name="funcao" value="resultadoCadastroTurma">
                      <table cellpadding="0" cellspacing="0" border="0" class="form_table">
                      <tr>
                      <td valign="middle" align="right">Selecione a Disciplina:
                      </td>
                      <td valign="middle" align="left">
                      <select name="idDisciplina" class="inputgri">';
                      $disciplinas=self::$controlador->listar('Disciplina');
                      foreach ($disciplinas as $disciplina)
                        echo '<option value="'.$disciplina->id.'">'.$disciplina->nome.'</option>';
                      echo '</select>
                      </td>
                      </tr>
                      <tr>
                      <td valign="middle" align="right">Selecione o Professor:
                      </td>
                      <td valign="middle" align="left">
                      <select name="idProfessor" class="inputgri">';
                      $professores=self::$controlador->listar('Professor');
                      foreach ($professores as $professor)
                        echo '<option value="'.$professor->id.'">'.$professor->nome.'</option>';
                      echo '</select>
                      </td>
                      </tr>
                      <tr>
                      <td valign="middle" align="right">Código da Turma:</td>
                      <td valign="middle" align="left">
                      <input name="id" type="text" class="inputgri" />
                      </td>
                      </tr>
                      </table>
                      <p><input type="submit" class="button" value="Salvar" />
                      </form>
                      <form action="index.php" method="post">
                      <input type="hidden" name="funcao" value="listaTurma">
                      <input type="submit" class="button" value="Cancelar" /></p>
                      </form>';
    }

    public function inserirAlunoParte1(){
                 echo '<head>
                      <meta http-equiv="content-Type" content="text/html; charset=UTF8" />
                      </head>
                      <br/><h2> Seleção de Disciplina </h2>
                      <form action="index.php" method="post">
                      <input type="hidden" name="funcao" value="inserirAlunoNaTurma">
                      <table cellpadding="0" cellspacing="0" border="0" class="form_table">
                      <tr>
                      <td valign="middle" align="right">Selecione a Disciplina:
                      </td>
                      <td valign="middle" align="left">
                      <select name="idDisciplina" class="inputgri">';
                       $disciplinas=self::$controlador->listar('Disciplina');
                       foreach ($disciplinas as $disciplina)
                           echo '<option value="'.$disciplina->id.'">'.$disciplina->nome.'</option>';
                       echo '</select>
                      </td>
                      </tr>
                      </table>
                      <p><input type="submit" class="button" value="Buscar Turmas" /></p>
                      </form>';
    }

    public function inserirAlunoNaTurma(){
                $key=$_POST['idDisciplina'];
                echo '<head>
                      <meta http-equiv="content-Type" content="text/html; charset=UTF8" />
                      </head>
                      <br/><h2> Adicionar Aluno </h2>
                      <form action="index.php" method="post">
                      <input type="hidden" name="funcao" value="resultadoInsercaoAluno">
                      <input type="hidden" name="idDisciplina" value='.$key.'>
                      <table cellpadding="0" cellspacing="0" border="0" class="form_table">
                      <tr>
                      <td valign="middle" align="right">Selecione a Turma:
                      </td>
                      <td valign="middle" align="left">
                      <select name="idTurma" class="inputgri">';
                       $turmas=self::$controlador->listarTurmasDeDisciplina($key);
                       foreach ($turmas as $turma)
                           echo '<option value="'.$turma->id.'">'.$turma->id.'</option>';
                       echo '</select>
                      </td>
                      </tr>
                      <tr>
                      <td valign="middle" align="right">Selecione o Aluno:
                      </td>
                      <td valign="middle" align="left">
                      <select name="idAluno" class="inputgri">';
                       $alunos=self::$controlador->listar('Aluno');
                       foreach ($alunos as $aluno)
                           echo '<option value="'.$aluno->id.'">'.$aluno->nome.'</option>';
                       echo '</select>
                      </td>
                      </tr>
                      </table>
                      <p><input type="submit" class="button" value="Adicionar" /></p>
                      </form>';
    }

    public function resultadoInsercaoAluno(){
                    $diarioDeClasse = new DiarioDeClasse;
                    $diarioDeClasse->FK_ID_turma=$_POST['idTurma'];
                    $diarioDeClasse->FK_ID_disciplina=$_POST['idDisciplina'];
                    $diarioDeClasse->FK_ID_aluno=$_POST['idAluno'];
                    self::$controlador->salvar($diarioDeClasse);
                    echo '<font color="green">Aluno inserido com sucesso na Turma!!</font><br/>';
                    $this->listaAlunosDaTurmaParte3();
    }

    public function resultadoCadastroTurma(){
                    $turma = new Turma;
                    $turma->id=$_POST['id'];
                    $turma->FK_ID_disciplina=$_POST['idDisciplina'];
                    $turma->FK_ID_professor=$_POST['idProfessor'];
                    self::$controlador->salvar($turma);
                    echo '<font color="green">Turma cadastrada com sucesso!!</font><br/>';
                    $this->listaTurma();
    }

    public function resultadoBuscaTurma(){
                $turma=self::$controlador->buscar($_POST['idTurma'],$_POST['idDisciplina'],'Turma');
                echo '<head>
                      <meta http-equiv="content-Type" content="text/html; charset=UTF8" />
                      </head>
                      <br/><h2> Detalhes da Turma </h2>
                      <form name="formRBusca" action="index.php" method="post">
                      <input type="hidden" name="funcao" value="resultadoExcluirTurma">
                      <input type="hidden" name="id" value="'.$turma->id.'">
                      <table cellpadding="0" cellspacing="0" border="0" class="form_table">
                      <tr>
                      <td valign="middle" align="right">Disciplina:</td>
                      <td valign="middle" align="left">'.$turma->FK_ID_disciplina.'</td>
                      </tr>
                      <tr>
                      <td valign="middle" align="right">Professor:</td>
                      <td valign="middle" align="left">'.self::$controlador->buscar($turma->FK_ID_professor,'Professor')->nome.'</td>
                      </tr>
                      <tr>
                      <td valign="middle" align="right">Código da Turma:</td>
                      <td valign="middle" align="left">'.$turma->id.'</td>
                      </tr>
                      </table>
                      <p><input type="submit" class="button" value="Excluir" /></p>
                      </form>';
    }

    public function listaTurma(){
                echo '<head>
                      <meta http-equiv="content-Type" content="text/html; charset=UTF8" />
                      </head>
                      <br/><h2> Lista de Turmas </h2>
                      <form name="formLista" action="index.php" method="post">
                      <input type="hidden" name="funcao" value="">
                      <input type="hidden" name="id" value="">
                      <input type="hidden" name="idDisciplina" value="">
                      <table cellpadding="0" cellspacing="0" border="0" width="100%" class="table">
                      <!-- table header -->
                      <tr class="table_header">
                      <td valign="middle" align="left">Código da Disciplina</td>
                      <td valign="middle" align="left">Código da Turma</td>
                      <td valign="middle" align="left">Nome do Professor</td>
                      <td valign="middle" align="left">Opções</td>
                      </tr>';
                    $turmas=self::$controlador->listar('Turma');
                    foreach ($turmas as $turma)
                    {
                        echo '<!-- row type one -->
                              <tr class="row1">
                              <td valign="middle" align="left">'.$turma->FK_ID_disciplina.'</td>
                              <td valign="middle" align="left">'.$turma->id.'</td>
                              <td valign="middle" align="left">'.self::$controlador->buscar($turma->FK_ID_professor,'Professor')->nome.'</td>
                              <td valign="middle" align="left"><a href="#"><div OnClick="document.formLista.funcao.value='."'resultadoExcluirTurma'".'; document.formLista.id.value='."'".$turma->id."'".'; document.formLista.idDisciplina.value='."'".$turma->FK_ID_disciplina."'".';document.formLista.submit();">Excluir</div></a></td>
                              </tr>';
                    }
                    echo '</table>
                          </form>
                          <form action="index.php" method="post">
                          <input type="hidden" name="funcao" value="cadastroTurma">
                          <input type="submit" class="button" value="Nova Turma" /></p>
                          </form>';
    }

    public function listaAlunosDaTurma(){
                echo '<head>
                      <meta http-equiv="content-Type" content="text/html; charset=UTF8" />
                      </head>
                      <br/><h2> Seleção de Disciplina </h2>
                      <form action="index.php" method="post">
                      <input type="hidden" name="funcao" value="listaAlunosDaTurmaParte2">
                      <table cellpadding="0" cellspacing="0" border="0" class="form_table">
                      <tr>
                      <td valign="middle" align="right">Selecione a Disciplina:
                      </td>
                      <td valign="middle" align="left">
                      <select name="idDisciplina" class="inputgri">';
                       $disciplinas=self::$controlador->listar('Disciplina');
                       foreach ($disciplinas as $disciplina)
                           echo '<option value="'.$disciplina->id.'">'.$disciplina->nome.'</option>';
                       echo '</select>
                      </td>
                      </tr>
                      </table>
                      <p><input type="submit" class="button" value="Buscar Turmas" /></p>
                      </form>';
    }

    public function listaAlunosDaTurmaParte2(){
                $key=$_POST['idDisciplina'];
                echo '<head>
                      <meta http-equiv="content-Type" content="text/html; charset=UTF8" />
                      </head>
                      <br/><h2> Seleção de Turma </h2>
                      <form action="index.php" method="post">
                      <input type="hidden" name="funcao" value="listaAlunosDaTurmaParte3">
                      <input type="hidden" name="idDisciplina" value='.$key.'>
                      <table cellpadding="0" cellspacing="0" border="0" class="form_table">
                      <tr>
                      <td valign="middle" align="right">Selecione a Turma:
                      </td>
                      <td valign="middle" align="left">
                      <select name="idTurma" class="inputgri">';
                       $turmas=self::$controlador->listarTurmasDeDisciplina($key);
                       foreach ($turmas as $turma)
                           echo '<option value="'.$turma->id.'">'.$turma->id.'</option>';
                       echo '</select>
                      </td>
                      </tr>
                      </table>
                      <p><input type="submit" class="button" value="Listar Alunos" /></p>
                      </form>';
    }

    public function listaAlunosDaTurmaParte3(){
                // exibe a lista dos alunos já cadastrados na turma
                $disciplina=self::$controlador->buscar($_POST['idDisciplina'],'Disciplina');
                $idTurma = $_POST['idTurma'];
                echo '<head>
                      <meta http-equiv="content-Type" content="text/html; charset=UTF8" />
                      </head>
                      <br/><h2> Lista dos Alunos da Turma Selecionada </h2>
                      <form name="formLista" action="index.php" method="post">
                      <input type="hidden" name="funcao" value="">
                      <input type="hidden" name="id" value="">
                      <input type="hidden" name="idDisciplina" value="">
                      <tr>
                      <td valign="middle" align="right">Disciplina:</td>
                      <td valign="middle" align="left">'.$disciplina->nome.'</td>
                      </tr><br/>
                      <tr>
                      <td valign="middle" align="right">Turma:</td>
                      <td valign="middle" align="left">'.$idTurma.'</td>
                      </tr><br/><br/><br/>
                      <!-- table header -->
                      <table cellpadding="0" cellspacing="0" border="0" width="100%" class="table">
                      <tr class="table_header">
                      <td valign="middle" align="left">Nome do Aluno</td>
                      <td valign="middle" align="left">Matrícula</td>
                      <td valign="middle" align="left">Opções</td>
                      </tr>';
                      $diarios=self::$controlador->listarAlunosDaTurma($disciplina->id,$idTurma);
                      foreach ($diarios as $diario)
                      {
                        echo '<!-- row type one -->
                              <tr class="row1">
                              <td valign="middle" align="left">'.self::$controlador->buscar($diario->FK_ID_aluno,'Aluno')->nome.'</td>
                              <td valign="middle" align="left">'.$diario->FK_ID_aluno.'</td>
                              <td valign="middle" align="left"><a href="#"><div OnClick="document.formLista.funcao.value='."'resultadoExcluirTurma'".'; document.formLista.id.value='."'".$turma->id."'".'; document.formLista.idDisciplina.value='."'".$turma->FK_ID_disciplina."'".';document.formLista.submit();">Excluir</div></a></td>
                              </tr>';
                      }
                      echo '</table>
                      </form>
                      <tr>
                      <td valign="middle" align="right">Clique no botão abaixo para adicionar um novo Aluno a essa Turma ou a outras Turmas dessa mesma Disciplina:
                      </td><br/><tr/>
                      <form action="index.php" method="post">
                      <br/>
                      <input type="hidden" name="funcao" value="inserirAlunoNaTurma">
                      <input type="hidden" name="idDisciplina" value="'.$disciplina->id.'">
                      <input type="submit" class="button" value="Adicionar Aluno" /></p>
                      </form>';
    }

    public function resultadoExcluirTurma(){
                    self::$controlador->excluirTurma($_POST['id'],$_POST['idDisciplina']);
                    echo '<font color="green">Turma excluída com sucesso!!</font><br/>';
                    $this->listaTurma();
    }

    // Métodos que redirecionam para páginas de manipulação
    // da entidade Professor
    public function buscaProfessor(){
                echo '<head>
                      <meta http-equiv="content-Type" content="text/html; charset=UTF8" />
                      </head>
                      <br/><h2> Pesquisa por Professor </h2>
                      <form name="formBusca" action="index.php" method="post">
                      <input type="hidden" name="funcao" value="resultadoBuscaProfessor">
                      <table cellpadding="0" cellspacing="0" border="0" class="form_table">
                      <tr>
                      <td valign="middle" align="right">Matrícula:</td>
                      <td valign="middle" align="left">
                      <input name="id" type="text" class="inputgri" />
                      </td>
                      </tr>
                      </table>
                      <p><input type="submit" class="button" value="Pesquisar" /></p>
                      </form>';
    }

    public function cadastroProfessor(){
                echo '<head>
                      <meta http-equiv="content-Type" content="text/html; charset=UTF8" />
                      </head>
                      <br/><h2> Novo Professor </h2>
                      <form action="index.php" method="post">
                      <input type="hidden" name="funcao" value="resultadoCadastroProfessor">
                      <table cellpadding="0" cellspacing="0" border="0" class="form_table">
                      <tr>
                      <td valign="middle" align="right">Nome:</td>
                      <td valign="middle" align="left">
                      <input name="nome" type="text" class="inputgri" />
                      </td>
                      </tr>
                      <tr>
                      <td valign="middle" align="right">E-mail:</td>
                      <td valign="middle" align="left">
                      <input name="email" type="text" class="inputgri" />
                      </td>
                      </tr>
                      <tr>
                      <td valign="middle" align="right">Senha:</td>
                      <td valign="middle" align="left">
                      <input name="senha" type="password" class="inputgri" name="pass3" />
                      </td>
                      </tr>
                      <tr>
                      <td valign="middle" align="right">Matrícula:</td>
                      <td valign="middle" align="left">
                      <input name="id" type="text" class="inputgri" />
                      </td>
                      </tr>
                      </table>
                      <p><input type="submit" class="button" value="Salvar" /></p>
                      </form>
                      <form action="index.php" method="post">
                      <input type="hidden" name="funcao" value="listaProfessor">
                      <input type="submit" class="button" value="Cancelar" /></p>
                      </form>';
    }

    public function resultadoCadastroProfessor(){
                    $professor = new Professor;
                    $professor->id=$_POST['id'];
                    $professor->nome=$_POST['nome'];
                    $professor->email=$_POST['email'];
                    $professor->senha=$_POST['senha'];
                    self::$controlador->salvar($professor,'Professor');
                    echo '<font color="green">Professor cadastrado com sucesso!!</font><br/>';
                    $this->listaProfessor();
    }

    public function resultadoBuscaProfessor(){
                $professor=self::$controlador->buscar($_POST['id'],'Professor');
                echo '<head>
                      <meta http-equiv="content-Type" content="text/html; charset=UTF8" />
                      </head>
                      <br/><h2> Detalhes do Professor </h2>
                      <form name="formRBusca" action="index.php" method="post">
                      <input type="hidden" name="funcao" value="resultadoExcluirProfessor">
                      <input type="hidden" name="id" value="'.$professor->id.'">
                      <table cellpadding="0" cellspacing="0" border="0" class="form_table">
                      <tr>
                      <td valign="middle" align="right">Nome:</td>
                      <td valign="middle" align="left">'.$professor->nome.'</td>
                      </tr>
                      <tr>
                      <td valign="middle" align="right">Email:</td>
                      <td valign="middle" align="left">'.$professor->email.'</td>
                      </tr>
                      <tr>
                      <td valign="middle" align="right">Matrícula:</td>
                      <td valign="middle" align="left">'.$professor->id.'</td>
                      </tr>
                      </table>
                      <p><input type="submit" class="button" value="Excluir" /></p>
                      </form>';
    }

    public function listaProfessor(){
                echo '<head>
                      <meta http-equiv="content-Type" content="text/html; charset=UTF8" />
                      </head>
                      <br/><h2> Lista de Professores </h2>
                      <form name="formLista" action="index.php" method="post">
                       <input type="hidden" name="funcao" value="">
                       <input type="hidden" name="id" value="">
                      <table cellpadding="0" cellspacing="0" border="0" width="100%" class="table">
                      <!-- table header -->
                      <tr class="table_header">
                      <td valign="middle" align="left">Matrícula</td>
                      <td valign="middle" align="left">Nome</td>
                      <td valign="middle" align="left">E-mail</td>
                      <td valign="middle" align="left">Opções</td>
                      </tr>';
                      $professores=self::$controlador->listar('Professor');
                      foreach ($professores as $professor)
                      {
                        echo '<!-- row type one -->
                              <tr class="row1">
                              <td valign="middle" align="left">'.$professor->id.'</td>
                              <td valign="middle" align="left"><a="#"><div OnClick="document.formLista.funcao.value='."'resultadoBuscaProfessor'".'; document.formLista.codigo.value='."'".$professor->id."'".'; document.formLista.submit();">'.$professor->nome.'</div></a></td>
                              <td valign="middle" align="left">'.$professor->email.'</td>
                              <td valign="middle" align="left"><a href="#"><div OnClick="document.formLista.funcao.value='."'resultadoExcluirProfessor'".'; document.formLista.id.value='."'".$professor->id."'".'; document.formLista.submit();">Excluir</div></a></td>
                              </tr>';
                      }
                      echo '</table>
                      </form>
                      <form action="index.php" method="post">
                      <br/>
                      <input type="hidden" name="funcao" value="cadastroProfessor">
                      <input type="submit" class="button" value="Novo Professor" /></p>
                      </form>';
    }

    public function resultadoExcluirProfessor(){
                    self::$controlador->excluir($_POST['id'],'Professor');
                    echo '<font color="green">Professor excluído com sucesso!!</font><br/>';
                    $this->listaProfessor();
    }

    // Métodos que redirecionam para páginas de manipulação
    // da entidade Aluno
    public function buscaAluno(){
                echo '<head>
                      <meta http-equiv="content-Type" content="text/html; charset=UTF8" />
                      </head>
                      <br/><h2> Pesquisa por Aluno </h2>
                      <form name="formBusca" action="index.php" method="post">
                      <input type="hidden" name="funcao" value="resultadoBuscaAluno">
                      <table cellpadding="0" cellspacing="0" border="0" class="form_table">
                      <tr>
                      <td valign="middle" align="right">Matrícula:</td>
                      <td valign="middle" align="left">
                      <input name="id" type="text" class="inputgri" />
                      </td>
                      </tr>
                      </table>
                      <p><input type="submit" class="button" value="Pesquisar" /></p>
                      </form>';
    }

    public function cadastroAluno(){
                echo '<head>
                      <meta http-equiv="content-Type" content="text/html; charset=UTF8" />
                      </head>
                      <br/><h2> Novo Aluno </h2>
                      <form action="index.php" method="post">
                      <input type="hidden" name="funcao" value="resultadoCadastroAluno">
                      <table cellpadding="0" cellspacing="0" border="0" class="form_table">
                      <tr>
                      <td valign="middle" align="right">Nome:</td>
                      <td valign="middle" align="left">
                      <input name="nome" type="text" class="inputgri" />
                      </td>
                      </tr>
                      <tr>
                      <td valign="middle" align="right">E-mail:</td>
                      <td valign="middle" align="left">
                      <input name="email" type="text" class="inputgri" />
                      </td>
                      </tr>
                      <tr>
                      <td valign="middle" align="right">Senha:</td>
                      <td valign="middle" align="left">
                      <input name="senha" type="password" class="inputgri"/>
                      </td>
                      </tr>
                      <tr>
                      <td valign="middle" align="right">Celular:</td>
                      <td valign="middle" align="left">
                      <input type="text" name="cel" class="inputgri" value=""/>(+55XX88888888)
                      </td>
                      </tr>
                      <tr>
                      <td valign="middle" align="right">Matrícula:</td>
                      <td valign="middle" align="left">
                      <input name="id" type="text" class="inputgri" />
                      </td>
                      </tr>
                      </table>
                      <p><input type="submit" class="button" value="Salvar" />
                      </form>
                      <form action="index.php" method="post">
                      <input type="hidden" name="funcao" value="listaAluno">
                      <input type="submit" class="button" value="Cancelar" /></p>
                      </form>';
    }

    public function resultadoBuscaAluno(){
                $aluno=self::$controlador->buscar($_POST['id'],'Aluno');
                echo '<head>
                      <meta http-equiv="content-Type" content="text/html; charset=UTF8" />
                      </head>
                      <br/><h2> Detalhes do Aluno </h2>
                      <form name="formRBusca" action="index.php" method="post">
                      <input type="hidden" name="funcao" value="resultadoExcluirAluno">
                      <input type="hidden" name="id" value="'.$aluno->id.'">
                      <table cellpadding="0" cellspacing="0" border="0" class="form_table">
                      <tr>
                      <td valign="middle" align="right">Nome:</td>
                      <td valign="middle" align="left">'.$aluno->nome.'</td>
                      </tr>
                      <tr>
                      <td valign="middle" align="right">Email:</td>
                      <td valign="middle" align="left">'.$aluno->email.'</td>
                      </tr>
                      <tr>
                      <td valign="middle" align="right">Celular:</td>
                      <td valign="middle" align="left">'.$aluno->cel.'</td>
                      </tr>
                      <tr>
                      <td valign="middle" align="right">Matrícula:</td>
                      <td valign="middle" align="left">'.$aluno->id.'</td>
                      </tr>
                      </table>
                      <p><input type="submit" class="button" value="Excluir" /></p>
                      </form>';
    }

    public function ListaAluno(){
                echo '<head>
                      <meta http-equiv="content-Type" content="text/html; charset=UTF8" />
                      </head>
                      <br/><h2> Lista de Alunos </h2>
                      <form name="formLista" action="index.php" method="post">
                      <input type="hidden" name="funcao" value="">
                      <input type="hidden" name="id" value="">
                      <table cellpadding="0" cellspacing="0" border="0" width="100%" class="table">
                      <!-- table header -->
                      <tr class="table_header">
                      <td valign="middle" align="left">Matrícula</td>
                      <td valign="middle" align="left">Nome</td>
                      <td valign="middle" align="left">E-mail</td>
                      <td valign="middle" align="left">Celular</td>
                      <td valign="middle" align="left">Opções</td>
                      </tr>';
                 $alunos=self::$controlador->listar('Aluno');
                 foreach ($alunos as $aluno)
                 {
                    echo '<!-- row type one -->
                          <tr class="row1">
                          <td valign="middle" align="left">'.$aluno->id.'</td>
                          <td valign="middle" align="left"><a><div OnClick="document.formLista.funcao.value='."'resultadoBuscaAluno'".'; document.formLista.codigo.value='."'".$aluno->id."'".'; document.formLista.submit();">'.$aluno->nome.'</div></a></td>
                          <td valign="middle" align="left">'.$aluno->email.'</td>
                          <td valign="middle" align="left">'.$aluno->cel.'</td>
                          <td valign="middle" align="left"><a href="#"><div OnClick="document.formLista.funcao.value='."'resultadoExcluirAluno'".'; document.formLista.id.value='."'".$aluno->id."'".'; document.formLista.submit();">Excluir</div></a></td>
                          </tr>';
                }
                echo '</table>
                      </form>
                      <form action="index.php" method="post">
                      <br/>
                      <input type="hidden" name="funcao" value="cadastroAluno">
                      <input type="submit" class="button" value="Novo Aluno" /></p>
                      </form>';
    }

    public function resultadoExcluirAluno(){
                    self::$controlador->excluir($_POST['id'],'Aluno');
                    echo '<font color="green">Aluno excluído com sucesso!!</font><br/>';
                    $this->listaAluno();
    }

    public function resultadoCadastroAluno(){
                    $aluno = new Aluno;
                    $aluno->nome=$_POST['nome'];
                    $aluno->cel=$_POST['cel'];
                    $aluno->senha=$_POST['senha'];
                    $aluno->id=$_POST['id'];
                    $aluno->email=$_POST['email'];
                    self::$controlador->salvar($aluno);
                    echo '<font color="green">Aluno cadastrado com sucesso!!</font><br/>';
                    $this->listaAluno();
    }

    public function logout(){
                   unset($_SESSION['flag_validacao']);
                   unset($_SESSION['usuario']);
                   unset($_SESSION['nivel']);
                   session_destroy();
                   header("refresh: 0; url=index.php");
   }
}
?>
